﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;

namespace BankRemoteSystem.BL
{
    class AccountBO
    {
        DataSet dt;
        DAL.AccountAO account;
        public Entities.Account getAccoutbyUserID(String userName)
        {
            account = new DAL.AccountAO();
            SqlDataReader dr = account.getAccoutbyUserID(userName);
            if (dr.Read())
            {
                Entities.Account c = new Entities.Account();
                c.AccountID = dr["accountID"].ToString();
                c.UserID = dr["userID"].ToString();
                c.TypeID = dr["typeID"].ToString();
                c.Balance = Convert.ToInt32(dr["balance"].ToString());
                c.CurrencyCode = dr["currencyCode"].ToString();
                c.Withdrawable = Convert.ToBoolean(dr["withdrawable"].ToString());
                c.Depositable = Convert.ToBoolean(dr["depositable"].ToString());
                return c;
            }
            return null;
        }

        public bool updateBalance(string accID, int balance)
        {            
            account = new DAL.AccountAO();
            if (account.updateBalance(accID, balance))
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        public bool addBalance(string accID, int balance)
        {
            account = new DAL.AccountAO();
            if (account.addBalance(accID, balance))
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        public DataSet getAllAccount()
        {
            DAL.Connection con = new DAL.Connection();
            dt = new DataSet();
            string sql = "select * from Account";
            dt = con.ExecuteQueryDataSet(sql, CommandType.Text, null, "Account");
            return dt;
        }
    }
}
